{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "cee85286-fcfe-452b-9017-7c0bce8168bf",
   "metadata": {},
   "outputs": [],
   "source": [
    "from fairchem.core import FAIRChemCalculator\n",
    "import ase.io\n",
    "from ase.optimize import LBFGS\n",
    "\n",
    "from fairchem.data.oc.core import Adsorbate, AdsorbateSlabConfig, Bulk, Slab\n",
    "import os\n",
    "from glob import glob\n",
    "import pandas as pd\n",
    "from fairchem.data.oc.utils.vasp import write_vasp_input_files"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3439e018-cacf-4fd5-adab-ec2344199e54",
   "metadata": {},
   "source": [
    "## Define desired adsorbate+slab system\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "a0060042-a46f-4a68-9336-cea1f021e049",
   "metadata": {},
   "outputs": [],
   "source": [
    "bulk_src_id = \"mp-30\"\n",
    "adsorbate_smiles = \"*CO\"\n",
    "\n",
    "bulk = Bulk(bulk_src_id_from_db = bulk_src_id)\n",
    "adsorbate = Adsorbate(adsorbate_smiles_from_db=adsorbate_smiles)\n",
    "slabs = Slab.from_bulk_get_specific_millers(bulk = bulk, specific_millers=(1,1,1))\n",
    "\n",
    "# There may be multiple slabs with this miller index.\n",
    "# For demonstrative purposes we will take the first entry.\n",
    "slab = slabs[0]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a774b7f5-e662-4959-9202-660d7bcaaacd",
   "metadata": {
    "tags": []
   },
   "source": [
    "# AdsorbML"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "8b97503b-6a8e-4a6a-9f3e-8200a78fc6b2",
   "metadata": {},
   "outputs": [],
   "source": [
    "calc = FAIRChemCalculator(hf_hub_filename=\"uma_sm.pt\", device=\"cuda\", task_name=\"oc20\")\n",
    "adsorption_energy_model = False"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "63d4fc1e-357b-4984-8222-9aade88b01ce",
   "metadata": {},
   "source": [
    "### Automated\n",
    "\n",
    "More details on the automated pipeline can be found at https://github.com/facebookresearch/fairchem/blob/main/src/fairchem/core/components/calculate/recipes/adsorbml.py#L316."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "7220dab5-38bf-4a95-acf6-581ed8b10f93",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "       Step     Time          Energy          fmax\n",
      "LBFGS:    0 15:21:19     -300.187740        0.048987\n",
      "LBFGS:    1 15:21:19     -300.188282        0.046745\n",
      "LBFGS:    2 15:21:19     -300.194195        0.005680\n",
      "       Step     Time          Energy          fmax\n",
      "LBFGS:    0 15:21:19     -333.950279        2.272333\n",
      "LBFGS:    1 15:21:19     -334.014906        1.085944\n",
      "LBFGS:    2 15:21:20     -334.051695        0.802282\n",
      "LBFGS:    3 15:21:20     -334.168344        1.425189\n",
      "LBFGS:    4 15:21:20     -334.201616        0.991624\n",
      "LBFGS:    5 15:21:20     -334.307863        0.454191\n",
      "LBFGS:    6 15:21:20     -334.329063        0.468656\n",
      "LBFGS:    7 15:21:20     -334.365997        0.546173\n",
      "LBFGS:    8 15:21:20     -334.407471        0.623766\n",
      "LBFGS:    9 15:21:20     -334.437610        0.340172\n",
      "LBFGS:   10 15:21:21     -334.449693        0.289551\n",
      "LBFGS:   11 15:21:21     -334.460455        0.297633\n",
      "LBFGS:   12 15:21:21     -334.474140        0.409112\n",
      "LBFGS:   13 15:21:21     -334.485840        0.300160\n",
      "LBFGS:   14 15:21:21     -334.493172        0.297545\n",
      "LBFGS:   15 15:21:21     -334.498386        0.184185\n",
      "LBFGS:   16 15:21:21     -334.502661        0.172219\n",
      "LBFGS:   17 15:21:21     -334.506145        0.187628\n",
      "LBFGS:   18 15:21:22     -334.509470        0.181198\n",
      "LBFGS:   19 15:21:22     -334.513719        0.216578\n",
      "LBFGS:   20 15:21:22     -334.518657        0.251597\n",
      "       Step     Time          Energy          fmax\n",
      "LBFGS:    0 15:21:22     -334.141115        1.670260\n",
      "LBFGS:    1 15:21:22     -334.174745        0.753937\n",
      "LBFGS:    2 15:21:22     -334.188146        0.363220\n",
      "LBFGS:    3 15:21:22     -334.227081        0.477617\n",
      "LBFGS:    4 15:21:22     -334.236833        0.427724\n",
      "LBFGS:    5 15:21:23     -334.243418        0.220533\n",
      "LBFGS:    6 15:21:23     -334.247902        0.214048\n",
      "LBFGS:    7 15:21:23     -334.252176        0.215822\n",
      "LBFGS:    8 15:21:23     -334.255586        0.165577\n",
      "LBFGS:    9 15:21:23     -334.258989        0.176218\n",
      "LBFGS:   10 15:21:23     -334.263058        0.250037\n",
      "LBFGS:   11 15:21:23     -334.267290        0.303349\n",
      "LBFGS:   12 15:21:24     -334.271078        0.222082\n",
      "LBFGS:   13 15:21:24     -334.274505        0.207782\n",
      "LBFGS:   14 15:21:24     -334.278066        0.208131\n",
      "LBFGS:   15 15:21:24     -334.282509        0.261225\n",
      "LBFGS:   16 15:21:24     -334.287445        0.290495\n",
      "LBFGS:   17 15:21:24     -334.291538        0.233074\n",
      "LBFGS:   18 15:21:24     -334.294315        0.128525\n",
      "LBFGS:   19 15:21:24     -334.296243        0.123187\n",
      "LBFGS:   20 15:21:25     -334.298195        0.198466\n",
      "       Step     Time          Energy          fmax\n",
      "LBFGS:    0 15:21:25     -334.367136        2.852595\n",
      "LBFGS:    1 15:21:25     -334.451711        1.751122\n",
      "LBFGS:    2 15:21:25     -334.486234        0.835419\n",
      "LBFGS:    3 15:21:25     -334.515634        0.718246\n",
      "LBFGS:    4 15:21:25     -334.581779        1.107969\n",
      "LBFGS:    5 15:21:25     -334.590805        0.622350\n",
      "LBFGS:    6 15:21:25     -334.596861        0.280277\n",
      "LBFGS:    7 15:21:26     -334.598615        0.299213\n",
      "LBFGS:    8 15:21:26     -334.604946        0.172670\n",
      "LBFGS:    9 15:21:26     -334.607776        0.209281\n",
      "LBFGS:   10 15:21:26     -334.612366        0.219552\n",
      "LBFGS:   11 15:21:26     -334.615566        0.202447\n",
      "LBFGS:   12 15:21:26     -334.618309        0.166049\n",
      "LBFGS:   13 15:21:26     -334.620643        0.143137\n",
      "LBFGS:   14 15:21:26     -334.623085        0.210225\n",
      "LBFGS:   15 15:21:27     -334.626018        0.280274\n",
      "LBFGS:   16 15:21:27     -334.628914        0.258845\n",
      "LBFGS:   17 15:21:27     -334.631349        0.172757\n",
      "LBFGS:   18 15:21:27     -334.633249        0.134923\n",
      "LBFGS:   19 15:21:27     -334.634645        0.129743\n",
      "LBFGS:   20 15:21:27     -334.635843        0.159375\n",
      "       Step     Time          Energy          fmax\n",
      "LBFGS:    0 15:21:27     -334.396601        2.161543\n",
      "LBFGS:    1 15:21:27     -334.448822        1.054668\n",
      "LBFGS:    2 15:21:28     -334.468952        0.548070\n",
      "LBFGS:    3 15:21:28     -334.507961        0.632466\n",
      "LBFGS:    4 15:21:28     -334.537672        0.883708\n",
      "LBFGS:    5 15:21:28     -334.548212        0.561108\n",
      "LBFGS:    6 15:21:28     -334.556125        0.186011\n",
      "LBFGS:    7 15:21:28     -334.558872        0.259675\n",
      "LBFGS:    8 15:21:28     -334.563761        0.228833\n",
      "LBFGS:    9 15:21:28     -334.567283        0.163509\n",
      "LBFGS:   10 15:21:29     -334.570852        0.200083\n",
      "LBFGS:   11 15:21:29     -334.573341        0.216683\n",
      "LBFGS:   12 15:21:29     -334.575222        0.165631\n",
      "LBFGS:   13 15:21:29     -334.576906        0.112880\n",
      "LBFGS:   14 15:21:29     -334.578621        0.129302\n",
      "LBFGS:   15 15:21:29     -334.580242        0.153682\n",
      "LBFGS:   16 15:21:29     -334.581489        0.140407\n",
      "LBFGS:   17 15:21:29     -334.582365        0.097057\n",
      "LBFGS:   18 15:21:30     -334.583078        0.093118\n",
      "LBFGS:   19 15:21:30     -334.583681        0.077778\n",
      "LBFGS:   20 15:21:30     -334.584255        0.090274\n",
      "       Step     Time          Energy          fmax\n",
      "LBFGS:    0 15:21:30     -333.996500        2.490288\n",
      "LBFGS:    1 15:21:30     -334.078203        1.278803\n",
      "LBFGS:    2 15:21:30     -334.146236        1.205340\n",
      "LBFGS:    3 15:21:30     -334.274715        2.167408\n",
      "LBFGS:    4 15:21:30     -334.331308        0.986549\n",
      "LBFGS:    5 15:21:31     -334.377825        0.593894\n",
      "LBFGS:    6 15:21:31     -334.446028        0.511533\n",
      "LBFGS:    7 15:21:31     -334.460274        0.515521\n",
      "LBFGS:    8 15:21:31     -334.494505        0.458458\n",
      "LBFGS:    9 15:21:31     -334.517277        0.376856\n",
      "LBFGS:   10 15:21:31     -334.529468        0.280553\n",
      "LBFGS:   11 15:21:31     -334.536098        0.243944\n",
      "LBFGS:   12 15:21:31     -334.547527        0.281722\n",
      "LBFGS:   13 15:21:32     -334.558050        0.308172\n",
      "LBFGS:   14 15:21:32     -334.566271        0.222530\n",
      "LBFGS:   15 15:21:32     -334.570961        0.189632\n",
      "LBFGS:   16 15:21:32     -334.575247        0.196575\n",
      "LBFGS:   17 15:21:32     -334.579374        0.173057\n",
      "LBFGS:   18 15:21:32     -334.582855        0.152537\n",
      "LBFGS:   19 15:21:32     -334.586422        0.167019\n",
      "LBFGS:   20 15:21:32     -334.590778        0.199029\n",
      "       Step     Time          Energy          fmax\n",
      "LBFGS:    0 15:21:33     -333.921068        2.242018\n",
      "LBFGS:    1 15:21:33     -333.974994        1.226273\n",
      "LBFGS:    2 15:21:33     -333.997019        0.586155\n",
      "LBFGS:    3 15:21:33     -334.042988        0.831985\n",
      "LBFGS:    4 15:21:33     -334.074844        0.934367\n",
      "LBFGS:    5 15:21:33     -334.089153        0.534069\n",
      "LBFGS:    6 15:21:33     -334.097238        0.234008\n",
      "LBFGS:    7 15:21:33     -334.104082        0.491718\n",
      "LBFGS:    8 15:21:34     -334.121542        0.868297\n",
      "LBFGS:    9 15:21:34     -334.145243        0.896622\n",
      "LBFGS:   10 15:21:34     -334.168081        0.541366\n",
      "LBFGS:   11 15:21:34     -334.186025        0.425227\n",
      "LBFGS:   12 15:21:34     -334.212133        0.732012\n",
      "LBFGS:   13 15:21:34     -334.243978        1.090527\n",
      "LBFGS:   14 15:21:34     -334.284885        1.109451\n",
      "LBFGS:   15 15:21:34     -334.326013        0.748725\n",
      "LBFGS:   16 15:21:35     -334.364036        0.608023\n",
      "LBFGS:   17 15:21:35     -334.395178        0.663711\n",
      "LBFGS:   18 15:21:35     -334.420318        0.490723\n",
      "LBFGS:   19 15:21:35     -334.431051        0.741292\n",
      "LBFGS:   20 15:21:35     -334.444795        0.352420\n",
      "       Step     Time          Energy          fmax\n",
      "LBFGS:    0 15:21:35     -334.019756        2.506824\n",
      "LBFGS:    1 15:21:35     -334.105177        1.305444\n",
      "LBFGS:    2 15:21:35     -334.172874        1.160150\n",
      "LBFGS:    3 15:21:36     -334.266157        2.974194\n",
      "LBFGS:    4 15:21:36     -334.377752        0.711254\n",
      "LBFGS:    5 15:21:36     -334.413002        0.633245\n",
      "LBFGS:    6 15:21:36     -334.483417        0.545490\n",
      "LBFGS:    7 15:21:36     -334.497347        0.346665\n",
      "LBFGS:    8 15:21:36     -334.514595        0.431346\n",
      "LBFGS:    9 15:21:36     -334.528147        0.462895\n",
      "LBFGS:   10 15:21:36     -334.538065        0.257359\n",
      "LBFGS:   11 15:21:37     -334.542232        0.188303\n",
      "LBFGS:   12 15:21:37     -334.546224        0.240374\n",
      "LBFGS:   13 15:21:37     -334.551025        0.347306\n",
      "LBFGS:   14 15:21:37     -334.556486        0.335910\n",
      "LBFGS:   15 15:21:37     -334.560991        0.188450\n",
      "LBFGS:   16 15:21:37     -334.564159        0.161734\n",
      "LBFGS:   17 15:21:37     -334.566725        0.166010\n",
      "LBFGS:   18 15:21:37     -334.569591        0.248926\n",
      "LBFGS:   19 15:21:38     -334.572815        0.253509\n",
      "LBFGS:   20 15:21:38     -334.576446        0.192177\n",
      "       Step     Time          Energy          fmax\n",
      "LBFGS:    0 15:21:38     -334.166471        1.633252\n",
      "LBFGS:    1 15:21:38     -334.204305        0.790558\n",
      "LBFGS:    2 15:21:38     -334.223450        0.591738\n",
      "LBFGS:    3 15:21:38     -334.300764        0.839228\n",
      "LBFGS:    4 15:21:38     -334.311630        0.544393\n",
      "LBFGS:    5 15:21:39     -334.333765        0.411686\n",
      "LBFGS:    6 15:21:39     -334.344944        0.382912\n",
      "LBFGS:    7 15:21:39     -334.359730        0.299531\n",
      "LBFGS:    8 15:21:39     -334.372564        0.336042\n",
      "LBFGS:    9 15:21:39     -334.389160        0.352764\n",
      "LBFGS:   10 15:21:39     -334.400774        0.409493\n",
      "LBFGS:   11 15:21:39     -334.408850        0.367214\n",
      "LBFGS:   12 15:21:39     -334.415455        0.283234\n",
      "LBFGS:   13 15:21:40     -334.422512        0.282633\n",
      "LBFGS:   14 15:21:40     -334.429680        0.420137\n",
      "LBFGS:   15 15:21:40     -334.433414        0.282969\n",
      "LBFGS:   16 15:21:40     -334.438288        0.222703\n",
      "LBFGS:   17 15:21:40     -334.441231        0.224396\n",
      "LBFGS:   18 15:21:40     -334.445219        0.198265\n",
      "LBFGS:   19 15:21:40     -334.448835        0.193995\n",
      "LBFGS:   20 15:21:40     -334.453049        0.300850\n",
      "       Step     Time          Energy          fmax\n",
      "LBFGS:    0 15:21:41     -334.338625        2.603666\n",
      "LBFGS:    1 15:21:41     -334.408628        1.486375\n",
      "LBFGS:    2 15:21:41     -334.434883        0.599442\n",
      "LBFGS:    3 15:21:41     -334.456714        0.543855\n",
      "LBFGS:    4 15:21:41     -334.507133        0.986853\n",
      "LBFGS:    5 15:21:41     -334.516594        0.617320\n",
      "LBFGS:    6 15:21:41     -334.524139        0.267052\n",
      "LBFGS:    7 15:21:41     -334.526644        0.307752\n",
      "LBFGS:    8 15:21:42     -334.532516        0.200297\n",
      "LBFGS:    9 15:21:42     -334.535293        0.160177\n",
      "LBFGS:   10 15:21:42     -334.539303        0.210905\n",
      "LBFGS:   11 15:21:42     -334.542641        0.263253\n",
      "LBFGS:   12 15:21:42     -334.545492        0.187122\n",
      "LBFGS:   13 15:21:42     -334.547764        0.139682\n",
      "LBFGS:   14 15:21:42     -334.549967        0.165029\n",
      "LBFGS:   15 15:21:42     -334.552559        0.268099\n",
      "LBFGS:   16 15:21:43     -334.555342        0.275143\n",
      "LBFGS:   17 15:21:43     -334.557611        0.190358\n",
      "LBFGS:   18 15:21:43     -334.559349        0.136105\n",
      "LBFGS:   19 15:21:43     -334.560753        0.117428\n",
      "LBFGS:   20 15:21:43     -334.562208        0.182235\n",
      "       Step     Time          Energy          fmax\n",
      "LBFGS:    0 15:21:43     -334.060760        1.765678\n",
      "LBFGS:    1 15:21:43     -334.108480        0.830127\n",
      "LBFGS:    2 15:21:43     -334.131088        0.643145\n",
      "LBFGS:    3 15:21:44     -334.216320        0.759600\n",
      "LBFGS:    4 15:21:44     -334.244049        0.792188\n",
      "LBFGS:    5 15:21:44     -334.269262        0.583671\n",
      "LBFGS:    6 15:21:44     -334.287828        0.448193\n",
      "LBFGS:    7 15:21:44     -334.313042        0.765149\n",
      "LBFGS:    8 15:21:44     -334.339796        0.864524\n",
      "LBFGS:    9 15:21:44     -334.362697        0.659597\n",
      "LBFGS:   10 15:21:44     -334.378605        0.387285\n",
      "LBFGS:   11 15:21:45     -334.388315        0.314529\n",
      "LBFGS:   12 15:21:45     -334.396066        0.335840\n",
      "LBFGS:   13 15:21:45     -334.410618        0.501265\n",
      "LBFGS:   14 15:21:45     -334.426376        0.423611\n",
      "LBFGS:   15 15:21:45     -334.439987        0.381364\n",
      "LBFGS:   16 15:21:45     -334.450134        0.349517\n",
      "LBFGS:   17 15:21:45     -334.458858        0.305763\n",
      "LBFGS:   18 15:21:45     -334.468096        0.344283\n",
      "LBFGS:   19 15:21:46     -334.477762        0.300965\n",
      "LBFGS:   20 15:21:46     -334.485721        0.279423\n"
     ]
    }
   ],
   "source": [
    "from fairchem.core.components.calculate.recipes.adsorbml import run_adsorbml\n",
    "\n",
    "outputs = run_adsorbml(\n",
    "    slab=slab,\n",
    "    adsorbate=adsorbate,\n",
    "    calculator=calc,\n",
    "    optimizer_cls=LBFGS,\n",
    "    fmax=0.02,\n",
    "    steps=20,         # Increase to 200 for practical application, 20 is used for demonstrations\n",
    "    num_placements=10, # Increase to 100 for practical application, 10 is used for demonstrations\n",
    "    reference_ml_energies=not adsorption_energy_model, #True if using a total energy model (i.e. UMA)\n",
    "    relaxed_slab_atoms=None,\n",
    "    place_on_relaxed_slab=False,\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "7017644c-1e2a-49a7-8c81-551bd22b73df",
   "metadata": {},
   "outputs": [],
   "source": [
    "top_candidates = outputs[\"adslabs\"]\n",
    "global_min_candidate = top_candidates[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "0f663116-b483-46bf-aa0c-8a661aa0863e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>input_atoms</th>\n",
       "      <th>atoms</th>\n",
       "      <th>results</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>{'atoms': (Atom('Cu', [np.float64(1.3000465215...</td>\n",
       "      <td>(Atom('Cu', [np.float64(1.3000465215529724), n...</td>\n",
       "      <td>{'energy': -334.6358430925115, 'forces': [[0.0...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>{'atoms': (Atom('Cu', [np.float64(1.3000465215...</td>\n",
       "      <td>(Atom('Cu', [np.float64(1.3000465215529724), n...</td>\n",
       "      <td>{'energy': -334.59077816636403, 'forces': [[0....</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>{'atoms': (Atom('Cu', [np.float64(1.3000465215...</td>\n",
       "      <td>(Atom('Cu', [np.float64(1.3000465215529724), n...</td>\n",
       "      <td>{'energy': -334.58425503404, 'forces': [[0.0, ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>{'atoms': (Atom('Cu', [np.float64(1.3000465215...</td>\n",
       "      <td>(Atom('Cu', [np.float64(1.3000465215529724), n...</td>\n",
       "      <td>{'energy': -334.5764463487371, 'forces': [[0.0...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>{'atoms': (Atom('Cu', [np.float64(1.3000465215...</td>\n",
       "      <td>(Atom('Cu', [np.float64(1.3000465215529724), n...</td>\n",
       "      <td>{'energy': -334.56220799119313, 'forces': [[0....</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>{'atoms': (Atom('Cu', [np.float64(1.3000465215...</td>\n",
       "      <td>(Atom('Cu', [np.float64(1.3000465215529724), n...</td>\n",
       "      <td>{'energy': -334.5186574998601, 'forces': [[0.0...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>{'atoms': (Atom('Cu', [np.float64(1.3000465215...</td>\n",
       "      <td>(Atom('Cu', [np.float64(1.3000465215529724), n...</td>\n",
       "      <td>{'energy': -334.4857214036687, 'forces': [[0.0...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>{'atoms': (Atom('Cu', [np.float64(1.3000465215...</td>\n",
       "      <td>(Atom('Cu', [np.float64(1.3000465215529724), n...</td>\n",
       "      <td>{'energy': -334.4530485215888, 'forces': [[0.0...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>{'atoms': (Atom('Cu', [np.float64(1.3000465215...</td>\n",
       "      <td>(Atom('Cu', [np.float64(1.3000465215529724), n...</td>\n",
       "      <td>{'energy': -334.4447954240544, 'forces': [[0.0...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>{'atoms': (Atom('Cu', [np.float64(1.3000465215...</td>\n",
       "      <td>(Atom('Cu', [np.float64(1.3000465215529724), n...</td>\n",
       "      <td>{'energy': -334.29819470078786, 'forces': [[0....</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                         input_atoms  \\\n",
       "0  {'atoms': (Atom('Cu', [np.float64(1.3000465215...   \n",
       "1  {'atoms': (Atom('Cu', [np.float64(1.3000465215...   \n",
       "2  {'atoms': (Atom('Cu', [np.float64(1.3000465215...   \n",
       "3  {'atoms': (Atom('Cu', [np.float64(1.3000465215...   \n",
       "4  {'atoms': (Atom('Cu', [np.float64(1.3000465215...   \n",
       "5  {'atoms': (Atom('Cu', [np.float64(1.3000465215...   \n",
       "6  {'atoms': (Atom('Cu', [np.float64(1.3000465215...   \n",
       "7  {'atoms': (Atom('Cu', [np.float64(1.3000465215...   \n",
       "8  {'atoms': (Atom('Cu', [np.float64(1.3000465215...   \n",
       "9  {'atoms': (Atom('Cu', [np.float64(1.3000465215...   \n",
       "\n",
       "                                               atoms  \\\n",
       "0  (Atom('Cu', [np.float64(1.3000465215529724), n...   \n",
       "1  (Atom('Cu', [np.float64(1.3000465215529724), n...   \n",
       "2  (Atom('Cu', [np.float64(1.3000465215529724), n...   \n",
       "3  (Atom('Cu', [np.float64(1.3000465215529724), n...   \n",
       "4  (Atom('Cu', [np.float64(1.3000465215529724), n...   \n",
       "5  (Atom('Cu', [np.float64(1.3000465215529724), n...   \n",
       "6  (Atom('Cu', [np.float64(1.3000465215529724), n...   \n",
       "7  (Atom('Cu', [np.float64(1.3000465215529724), n...   \n",
       "8  (Atom('Cu', [np.float64(1.3000465215529724), n...   \n",
       "9  (Atom('Cu', [np.float64(1.3000465215529724), n...   \n",
       "\n",
       "                                             results  \n",
       "0  {'energy': -334.6358430925115, 'forces': [[0.0...  \n",
       "1  {'energy': -334.59077816636403, 'forces': [[0....  \n",
       "2  {'energy': -334.58425503404, 'forces': [[0.0, ...  \n",
       "3  {'energy': -334.5764463487371, 'forces': [[0.0...  \n",
       "4  {'energy': -334.56220799119313, 'forces': [[0....  \n",
       "5  {'energy': -334.5186574998601, 'forces': [[0.0...  \n",
       "6  {'energy': -334.4857214036687, 'forces': [[0.0...  \n",
       "7  {'energy': -334.4530485215888, 'forces': [[0.0...  \n",
       "8  {'energy': -334.4447954240544, 'forces': [[0.0...  \n",
       "9  {'energy': -334.29819470078786, 'forces': [[0....  "
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "top_candidates = outputs[\"adslabs\"]\n",
    "pd.DataFrame(top_candidates)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fe926290-3bec-406c-83d3-fcb2eee76c0a",
   "metadata": {},
   "source": [
    "# Write VASP input files\n",
    "\n",
    "This assumes you have access to VASP pseudopotentials. The default VASP flags (which are equivalent to those used to make OC20) are located in `ocdata.utils.vasp`. Alternatively, you may pass your own vasp flags to the `write_vasp_input_files` function as `vasp_flags`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "5baeaa19-bc79-424c-8d1f-9b4a066a486c",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Grab the 5 systems with the lowest energy\n",
    "top_5_candidates = top_candidates[:5]\n",
    "\n",
    "# Write the inputs\n",
    "for idx, config in enumerate(top_5_candidates):\n",
    "    os.makedirs(f\"data/{idx}\", exist_ok=True)\n",
    "    write_vasp_input_files(config[\"atoms\"], outdir = f\"data/{idx}/\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "fc_250515",
   "language": "python",
   "name": "fc_250515"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
